`<!--
  -    Copyright (c) 2018-2025, bfcloud All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: bfcloud
  -->

<template>
  <div class="app-container calendar-list-container">
    <basic-container>
      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="5">
          <div class="user__tree boxsty">
            <el-input placeholder="输入关键字进行过滤" v-model="filterText" clearable></el-input>
            <el-tree ref="tree" :data="treeData" :props="defaultProps" :filter-node-method="filterNode"
                     class="filter-tree" node-key="id" highlight-current :default-expanded-keys="[1]" accordion
                     @node-click="getNodeData"/>
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :md="19">
          <div class="user__main boxsty filter-container">
            <div class="flex justifyContentSpaceBetween">
              <div class="tabletext">部门管理</div>
              <div class="tablelink">
                <el-link icon="el-icon-plus" v-if="deptManager_btn_add" type="primary" @click="handlerAdd"
                         :underline="false">添加
                </el-link>
                <el-link icon="el-icon-edit" v-if="deptManager_btn_edit" type="primary" @click="handlerEdit"
                         :underline="false">编辑
                </el-link>
                <el-link icon="el-icon-delete" v-if="deptManager_btn_del" type="danger" @click="handleDelete"
                         :underline="false">删除
                </el-link>
              </div>
            </div>

            <div class="box-card">
              <el-form ref="form" :label-position="labelPosition" :rules="rules" :model="form" label-width="120px">
                <el-form-item label="父级节点" prop="parentId">
                  <el-input v-model="form.parentId" disabled placeholder="请输入父级节点"/>
                </el-form-item>
                <el-form-item v-if="formEdit" label="节点编号" prop="deptId">
                  <el-input v-model="form.deptId" :disabled="formEdit" placeholder="节点编号"/>
                </el-form-item>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="部门名称" prop="name">
                      <el-input v-model="form.name" :disabled="formEdit" placeholder="请输入名称"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="部门编号" prop="deptCode">
                      <el-input v-model="form.deptCode" :disabled="formEdit" placeholder="请输入编号"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="16">
                    <el-form-item label="部门全称" prop="deptName">
                      <el-input v-model="form.deptName" :disabled="formEdit" placeholder="请输入全称"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="排序" prop="sort">
                      <el-input v-model="form.sort" :disabled="formEdit" :min="0" oninput="if(value<0)value=0" type="number" placeholder="请输入"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="10">
                    <el-form-item label="部门领导">
                      <!--                      <el-select-->
                      <!--                        v-model="form.deptLeaderId"-->
                      <!--                        :disabled="formEdit"-->
                      <!--                        filterable-->
                      <!--                        remote-->
                      <!--                        reserve-keyword-->
                      <!--                        placeholder="请选择领导"-->
                      <!--                        :remote-method="remoteMethod"-->
                      <!--                        :loading="loading"-->
                      <!--                        @change="selectDeptLeaderId"-->
                      <!--                      >-->
                      <!--                        <el-option-->
                      <!--                          v-for="item in options"-->
                      <!--                          :key="item.userId"-->
                      <!--                          :label="item.ryName"-->
                      <!--                          :value="item.userId">-->
                      <!--                        </el-option>-->
                      <!--                      </el-select>-->
                      <el-input v-model="form.deptLeaderName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    &nbsp;<el-button @click="selectCheckUser('机构')" :disabled="formEdit">选择</el-button>
                  </el-col>
                  <el-col :span="10">

                    <el-form-item label="部门副职领导">
                      <el-input v-model="form.deptLeaderNames" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    &nbsp;<el-button @click="selectCheckUser('副手')" :disabled="formEdit">选择</el-button>
                  </el-col>
                </el-row>

                <el-row>
                  <el-col :span="10">
                    <el-form-item label="奖金管理员" prop="jgGlUserName">
                      <el-input v-model="form.deptJjadminName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    &nbsp;<el-button @click="selectCheckUser('奖金')" :disabled="formEdit">选择</el-button>
                  </el-col>
                  <el-col :span="10">
                    <el-form-item label="奖金审核员" v-show="false">
                      <el-input v-model="form.deptJjfafangName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">&nbsp;
                    <el-button v-show="false" @click="selectCheckUser('发放')" :disabled="formEdit">选择</el-button>
                  </el-col>


                </el-row>

                <el-row>
                  <el-col :span="10">
                    <el-form-item label="合同管理员" prop="deptHtruadminName">
                      <el-input v-model="form.deptHtruadminName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    &nbsp;<el-button @click="htselectCheckUser()" :disabled="formEdit">选择</el-button>
                  </el-col>
                  <el-col :span="10">
                    <el-form-item label="考核管理员" prop="deptRckhadminName">
                      <el-input v-model="form.deptRckhadminName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    <el-button @click="selectCheckUser('考核')" :disabled="formEdit">选择</el-button>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="10">
                    <el-form-item label="日常管理员" prop="deptXrckhadminName">
                      <el-input v-model="form.deptXrckhadminName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    <el-button @click="selectCheckUser('新日常考核')" :disabled="formEdit">选择</el-button>
                  </el-col>

                  <el-col :span="10">
                    <el-form-item label="奖惩管理员" prop="deptJcrckhadminName">
                      <el-input v-model="form.deptJcrckhadminName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    <el-button @click="selectCheckUser('精准激励')" :disabled="formEdit">选择</el-button>
                  </el-col>
                </el-row>

                <el-row>
                  <el-col :span="10">
                    <el-form-item label="评分管理员" prop="deptPfdjadminName">
                      <el-input v-model="form.deptPfdjadminName" :disabled="true" placeholder="请选择"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2">
                    <el-button @click="selectCheckUser('评分等级')" :disabled="formEdit">选择</el-button>
                  </el-col>
                </el-row>
                <el-form-item v-if="formStatus == 'update'">
                  <el-button type="primary" @click="update">更新</el-button>
                  <el-button @click="onCancel">取消</el-button>
                </el-form-item>
                <el-form-item v-if="formStatus == 'create'">
                  <el-button type="primary" @click="create">保存</el-button>
                  <el-button @click="onCancel">取消</el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </el-col>
      </el-row>
    </basic-container>
    <!--奖金管理员-->
    <check-user-role ref="checkUserRole" :multiple='true' :roleCode="roleCode" :userIds='userRoleIds' @getUserList="getUserRoleList"></check-user-role>
    <!--机构负责人-->
    <check-user-all ref="checkUserAll" :multiple='false' :roleCode="roleCode" :userIds='userAllIds' @getUserList="getUserAllList"></check-user-all>
    <!--机构副手-->
    <check-user-second ref="checkUserSecond" :multiple='true' :roleCode="roleCode" :userIds='userSecondIds' @getUserList="getUserSecondList"></check-user-second>
    <!--奖金发放-->
    <check-user-give-out ref="checkUserGiveOut" :multiple='false'  :roleCode="roleCode" :userIds='userGiveOutIds' @getUserList="getUserGiveList"></check-user-give-out>
    <!--部门合同-->
    <check-user-contract ref="checkUserContract" :multiple='true' :roleCode="roleCode" :userIds='userContractIds' @getUserList="getUserContract"></check-user-contract>
    <!--部门日常考核-->
    <check-user-check ref="checkUserCheck" :multiple='true' :roleCode="roleCode" :userIds='userCheckIds' @getUserList="getUserCheck"></check-user-check>
    <!--新日常考核-->
    <check-user-xrckh ref="checkUserXrckh" :multiple='xrcOrpf' :roleCode="roleCode" :userIds='userXrckhIds' @getUserList="getUserXrckh"></check-user-xrckh>
    <!--新评分等级-->
    <check-user-pfdj ref="checkUserPfdj" :multiple='xrcOrpf' :roleCode="roleCode" :userIds='userPfdjIds' @getUserList="getUserPfdj"></check-user-pfdj>

    <!--奖惩日常考核-->
    <check-user-Jcrckh ref="checkUserJcrckh" :multiple='xrcOrpf' :roleCode="roleCode" :userIds='userJcrckhIds' @getUserList="getUserJcrckh"></check-user-Jcrckh>

    <!-- 合同 -->
    <htselectUser ref="htselectUser" :multiple='true' :roleCode="roleCode" :userIds='userContractIds' @getUserList="getUserContract"></htselectUser>
  </div>
</template>

<script>
    import {addObj, delObj, fetchTree, getObj, putObj,haveRepetManger} from '@/api/admin/dept'
    import {fetchList} from '@/api/admin/user'
    import {mapGetters} from 'vuex'
    import checkUserRole from '@/components/form/compound/selectUser'
    import checkUserAll from '@/components/form/compound/selectUser'
    import checkUserSecond from '@/components/form/compound/selectUser'
    import checkUserGiveOut from '@/components/form/compound/selectUser'
    import checkUserContract from '@/components/form/compound/selectUser'
    import checkUserCheck from '@/components/form/compound/selectUser'
    import htselectUser from '@/components/form/compound/htselectUser'
    import checkUserXrckh from '@/components/form/compound/selectUser'
    import checkUserPfdj from '@/components/form/compound/selectUser'

    import checkUserJcrckh from '@/components/form/compound/selectUser'
    export default {
        name: 'Dept',
        components:{
            checkUserRole,
            checkUserAll,
            checkUserSecond,
            checkUserGiveOut,
            checkUserContract,
            checkUserCheck,
            htselectUser,
            checkUserXrckh,
            checkUserPfdj,
            checkUserJcrckh
        },
        data() {
            return {
                xrcOrpf:false,
                roleCode:'',
                userRoleIds:[],
                userAllIds:[],
                userSecondIds:[],
                userGiveOutIds:[],
                userContractIds:[],
                userCheckIds:[],
                userXrckhIds:[],
                userPfdjIds:[],
                userJcrckhIds:[],
                filterText: "",
                list: null,
                total: null,
                formEdit: true,
                formAdd: true,
                formStatus: '',
                typeOptions: ['0', '1'],
                methodOptions: ['GET', 'POST', 'PUT', 'DELETE'],
                listQuery: {
                    name: undefined
                },
                treeData: [],
                defaultProps: {
                    children: 'children',
                    label: 'name'
                },
                rules: {
                    parentId: [
                        {required: true, message: '请输入父级节点', trigger: 'blur'}
                    ],
                    deptId: [
                        {required: true, message: '请输入节点编号', trigger: 'blur'}
                    ],
                    deptCode: [
                        {required: true, message: '请输入部门编号', trigger: 'blur'}
                    ],
                    deptName: [
                        {required: true, message: '请输入部门合称', trigger: 'blur'}
                    ],
                    name: [
                        {required: true, message: '请输入部门名称', trigger: 'blur'},
                        {min: 1, max: 32, message: '长度在 1 到 32 个字符', trigger: 'blur'}
                    ],
                    sort: [
                        {required: true, message: '请输入排序值', trigger: 'blur'}
                    ]
                },
                labelPosition: 'right',
                form: {
                    name: undefined,
                    sort: undefined,
                    parentId: undefined,
                    deptId: undefined,

                    //部门管理
                    deptLeaderId: "",
                    deptLeaderName: "",
                    // 部门管理副手
                    deptLeaderIds:"",
                    deptLeaderNames:"",
                    // 奖金管理
                    deptJjadminId: "",
                    deptJjadminName: "",
                    // 奖金发放
                    deptJjfafangId:"",
                    deptJjfafangName:"",
                    // 部门合同
                    deptHtruadminId:"",
                    deptHtruadminName:"",
                    // 部门日常考核
                    deptRckhadminId:"",
                    deptRckhadminName:"",
                    //新日常考核
                    deptXrckhadminId:"",
                    deptXrckhadminName:"",
                    //评分等级
                    deptPfdjadminId:"",
                    deptPfdjadminName:"",

                    //评分等级
                    deptJcrckhadminId:"",
                    deptJcrckhadminName:"",
                },
                currentId: 0,
                deptManager_btn_add: false,
                deptManager_btn_edit: false,
                deptManager_btn_del: false,
                options: [],
                loading: false
            }
        },
        created() {
            this.getList()
            this.deptManager_btn_add = this.permissions['sys_dept_add']
            this.deptManager_btn_edit = this.permissions['sys_dept_edit']
            this.deptManager_btn_del = this.permissions['sys_dept_del']
        },
        computed: {
            ...mapGetters([
                'elements',
                'permissions'
            ])
        },
        watch: {
            filterText(val) {
                this.$refs.tree.filter(val);
            }
        },
        methods: {
            //取得空值 增加弹错判断
            getBlankValue(value){
                let lResult = "";
                if(value === undefined || value === null){
                }else {
                    lResult = value;
                }
                return lResult;
            },
            selectCheckUser(vm){
                // if(this.dataForm.jgDeptId === ""){
                //   this.$notify.closeAll();
                //   this.$notify.error('请先在左侧选择部门');
                //   return;
                // }

                if(vm === "奖金"){
                    this.userAllIds = [];
                    this.userSecondIds = [];

                    this.roleCode = "JJ_SALARYADMIN";
                    this.userRoleIds = [];
                    this.userRoleIds.push(this.getBlankValue(this.form.deptJjadminId));

                    this.userGiveOutIds = [];
                    this.userContractIds = [];
                    this.userCheckIds = [];
                    this.userXrckhIds = [];

                    //防止数据慢于页面加载
                    this.$nextTick(()=>{
                        this.$refs.checkUserRole.init();
                    })

                }else if(vm === "机构"){
                    this.roleCode = "";

                    this.userAllIds = [];
                    this.userAllIds.push(this.getBlankValue(this.form.deptLeaderId));

                    this.userSecondIds = [];
                    this.userRoleIds = [];
                    this.userGiveOutIds = [];
                    this.userContractIds = [];
                    this.userCheckIds = [];
                    this.userXrckhIds = [];

                    this.$nextTick(()=>{
                        this.$refs.checkUserAll.init();
                    })
                }
                else if(vm === "副手"){
                    this.roleCode = "";

                    this.userAllIds = [];

                    this.userSecondIds = [];
                    this.userSecondIds.push(this.getBlankValue(this.form.deptLeaderIds));

                    this.userRoleIds = [];
                    this.userGiveOutIds = [];
                    this.userContractIds = [];
                    this.userCheckIds = [];
                    this.userXrckhIds = [];

                    this.$nextTick(()=>{
                        this.$refs.checkUserSecond.init();
                    })
                }
                else if(vm === "发放"){
                    this.roleCode = "JJ_SALARYGIVEOUT";

                    this.userAllIds = [];
                    this.userSecondIds = [];
                    this.userRoleIds = [];

                    this.userGiveOutIds = [];
                    this.userGiveOutIds.push(this.getBlankValue(this.form.deptJjfafangId));

                    this.userContractIds = [];
                    this.userCheckIds = [];
                    this.userXrckhIds = [];


                    this.$nextTick(()=>{
                        this.$refs.checkUserGiveOut.init();
                    })
                } else if(vm === "考核"){
                    this.roleCode = "";
                    this.userAllIds = [];
                    this.userSecondIds = [];
                    this.userRoleIds = [];
                    this.userGiveOutIds = [];
                    this.userContractIds = [];

                    this.userCheckIds = [];
                    this.userCheckIds.push(this.getBlankValue(this.form.deptRckhadminId));

                    this.$nextTick(()=>{
                        this.$refs.checkUserCheck.init();
                    })
                }else if(vm === "新日常考核"){

                    if(this.form.parentId == 0){
                        this.xrcOrpf = true;
                    }else{
                        this.xrcOrpf = false;
                    }
                    this.roleCode = "";//XRCKH_ADMIN
                    this.userAllIds = [];
                    this.userSecondIds = [];
                    this.userRoleIds = [];
                    this.userGiveOutIds = [];
                    this.userContractIds = [];

                    this.userXrckhIds = [];
                    this.userXrckhIds.push(this.getBlankValue(this.form.deptXrckhadminId));

                    this.$nextTick(()=>{
                        this.$refs.checkUserXrckh.init();
                    })
                }else if(vm === "评分等级"){

                    if(this.form.parentId == 0){
                        this.xrcOrpf = true;
                    }else{
                        this.xrcOrpf = false;
                    }
                    this.roleCode = "";//XRCKH_ADMIN
                    this.userAllIds = [];
                    this.userSecondIds = [];
                    this.userRoleIds = [];
                    this.userGiveOutIds = [];
                    this.userContractIds = [];

                    this.userPfdjIds = [];
                    this.userPfdjIds.push(this.getBlankValue(this.form.deptPfdjadminId));

                    this.$nextTick(()=>{
                        this.$refs.checkUserPfdj.init();
                    })
                }else if(vm === "精准激励"){

                  if(this.form.parentId == 0){
                    this.xrcOrpf = true;
                  }else{
                    this.xrcOrpf = false;
                  }
                  this.roleCode = "";//XRCKH_ADMIN
                  this.userAllIds = [];
                  this.userSecondIds = [];
                  this.userRoleIds = [];
                  this.userGiveOutIds = [];
                  this.userContractIds = [];

                  this.userJcrckhIds = [];
                  this.userJcrckhIds.push(this.getBlankValue(this.form.deptJcrckhadminId));

                  this.$nextTick(()=>{
                    this.$refs.checkUserJcrckh.init();
                  })
                }
            },
            htselectCheckUser(){
                var params = {
                    deptId:this.form.deptId,
                    roleCode:"HTRW_ADMIN"
                }
                this.roleCode = "HTRW_ADMIN";
                this.userAllIds = [];
                this.userSecondIds = [];
                this.userRoleIds = [];
                this.userGiveOutIds = [];

                this.userContractIds = [];
                this.userContractIds.push(this.getBlankValue(this.form.deptHtruadminId));

                this.userCheckIds = [];

                this.$nextTick(()=>{
                    this.$refs.htselectUser.init(params);
                })
            },
            //取得角色用户-奖金管理
            getUserRoleList(data){
                if(data.length === 0){
                    this.$set(this.form,'deptJjadminId',"")
                    this.$set(this.form,'deptJjadminName',"")
                    // return;
                }else {
                    const c1= this.getStrJoin("ryName",data);
                    const c2= this.getStrJoin("userId",data);

                    this.$set(this.form,'deptJjadminId',c2.join(','))
                    this.$set(this.form,'deptJjadminName',c1.join(','))
                }
            },
            // 取得角色用户-奖金发放
            getUserGiveList(data){
                if(data.length === 0){
                    this.$set(this.form,'deptJjfafangId',"")
                    this.$set(this.form,'deptJjfafangName',"")
                    // return;
                }else {
                    this.$set(this.form,'deptJjfafangId',data[0].userId)
                    this.$set(this.form,'deptJjfafangName',data[0].ryName)
                }
            },
            // 取得角色用户-部门合同
            getUserContract(data){
                if(data.length === 0){
                    this.form.deptHtruadminId = "";
                    this.form.deptHtruadminName = "";
                }else {
                    const c1= this.getStrJoin("ryName",data);
                    const c2= this.getStrJoin("userId",data);

                    this.form.deptHtruadminId = c2.join(',');
                    this.form.deptHtruadminName = c1.join(',');
                }
            },
            // 取得角色用户-部门日常考核
            getUserCheck(data){
                //console.log(data)
                if(data.length === 0){
                    this.form.deptRckhadminId = "";
                    this.form.deptRckhadminName = "";
                }else {
                    const c1= this.getStrJoin("ryName",data);
                    const c2= this.getStrJoin("userId",data);

                    this.form.deptRckhadminId =  c2.join(',');
                    this.form.deptRckhadminName = c1.join(',');
                }
            },
            // 取得角色用户-新日常考核
            getUserXrckh(data,type){
                if(data.length === 0){
                    this.form.deptXrckhadminId = "";
                    this.form.deptXrckhadminName = "";
                }else {
                    const c1= this.getStrJoin("ryName",data);
                    const c2= this.getStrJoin("userId",data);

                    this.form.deptXrckhadminId =  c2.join(',');
                    this.form.deptXrckhadminName = c1.join(',');
                }
            },
            // 取得角色用户-评分等级
            getUserPfdj(data){

                if(data.length === 0){
                    this.form.deptPfdjadminId = "";
                    this.form.deptPfdjadminName = "";
                }else {
                    const c1= this.getStrJoin("ryName",data);
                    const c2= this.getStrJoin("userId",data);

                    this.form.deptPfdjadminId =  c2.join(',');
                    this.form.deptPfdjadminName = c1.join(',');
                }
            },
          // 取得角色用户-奖惩日常考核
          getUserJcrckh(data){

            if(data.length === 0){
              this.form.deptJcrckhadminId = "";
              this.form.deptJcrckhadminName = "";
            }else {
              const c1= this.getStrJoin("ryName",data);
              const c2= this.getStrJoin("userId",data);

              this.form.deptJcrckhadminId =  c2.join(',');
              this.form.deptJcrckhadminName = c1.join(',');
            }
          },

            //取得所有用户(部门领导)
            getUserAllList(data){
                if(data.length === 0){
                    this.$set(this.form,'deptLeaderId',"")
                    this.$set(this.form,'deptLeaderName',"")
                    //return;
                }else {
                    this.$set(this.form,'deptLeaderId',data[0].userId)
                    this.$set(this.form,'deptLeaderName',data[0].ryName)
                }
            },
            //取得所有用户(部门副职)
            getUserSecondList(data){
                if(data.length === 0){
                    this.$set(this.form,'deptLeaderIds',"");
                    this.$set(this.form,'deptLeaderNames',"");
                }else{
                    const c1= this.getStrJoin("ryName",data);
                    const c2= this.getStrJoin("userId",data);
                    this.$set(this.form,'deptLeaderIds',c2.join(','));
                    this.$set(this.form,'deptLeaderNames',c1.join(','));
                }
            },
            //拼接字符串
            getStrJoin(strKey,strData){
                let lTemp = [];
                strData.map(item => {
                    lTemp.push(item[strKey]);
                })
                return lTemp;
            },
            remoteMethod(query) {
                if (query !== '') {
                    this.loading = true;
                    fetchList(Object.assign({
                        current: 1,
                        size: 50
                    }, {username: query})).then(response => {
                        // this.options = response.data.data.records;
                        this.loading = false
                    })
                } else {
                    // this.options = [];
                }
            },
            selectDeptLeaderId(v) {
                this.form.deptLeaderName = "";
                this.options.forEach(r => {
                    if (r.userId == v) {
                        this.form.deptLeaderName = r.ryName;
                    }
                })
            },
            getList() {
                fetchTree(this.listQuery).then(response => {
                    this.treeData = response.data.data
                })
            },
            filterNode(value, data) {
                if (!value) return true
                return data.name.indexOf(value) !== -1
            },
            getNodeData(data) {
                if (!this.formEdit) {
                    this.formStatus = 'update'
                }
                getObj(data.id).then(response => {
                    this.form = response.data.data
                    // if (this.form.deptLeaderId) {
                    //   this.options = [];
                    //   this.options.push({
                    //     userId: this.form.deptLeaderId,
                    //     ryName: this.form.deptLeaderName
                    //   })
                    // }
                })
                this.currentId = data.id
            },
            handlerEdit() {
                if (this.form.deptId) {
                    this.formEdit = false
                    this.formStatus = 'update'
                }
            },
            handlerAdd() {
                this.resetForm()
                this.formEdit = false
                this.formStatus = 'create'
            },
            handleDelete() {
                this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    delObj(this.currentId).then(() => {
                        this.getList()
                        this.resetForm()
                        this.onCancel()
                        this.$notify.closeAll();
                        this.$notify.success('删除成功')
                    })
                })
            },
            // 修改
            update() {
                this.$refs.form.validate((valid) => {
                    if (!valid) return
                    const cLeader = this.getUserSpecialId("部门领导");
                    // const cLeaderJj = this.getUserSpecialId("奖金管理员");

                    //部门领导验证
                    if(cLeader !== ""){
                        haveRepetManger(this.currentId,cLeader,"update","部门领导").then(res =>{
                            const cListLeader = res.data.data;
                            if(cListLeader.length > 0){
                                this.$notify.closeAll();
                                this.$notify.error(cListLeader[0].deptLeaderName + "已是" + cListLeader[0].deptName + "领导，请重新选择！");
                            }else {
                                this.addOrUpdate("update");
                            }
                        })
                    }else {
                        this.addOrUpdate("update");
                    }
                })
            },

            // 添加
            create() {
                this.$refs.form.validate((valid) => {
                    if (!valid) return;

                    const cLeader = this.getUserSpecialId("部门领导");

                    //部门领导验证
                    if(cLeader !== ""){
                        haveRepetManger(this.currentId,cLeader,"add","部门领导").then(res =>{
                            const cListLeader = res.data.data;
                            if(cListLeader.length > 0){
                                this.$notify.closeAll();
                                this.$notify.error(cListLeader[0].deptLeaderName + "已是" + cListLeader[0].deptName + "领导，请重新选择！");
                            }else {
                                this.addOrUpdate("add");
                            }
                        })
                    }else {
                        this.addOrUpdate("add");
                    }
                })
            },

            //原逻辑添加或修改
            addOrUpdate(vm){
                if(vm === "add"){
                    addObj(this.form).then(() => {
                        this.getList();
                        this.onCancel();
                        this.$notify.closeAll();
                        this.$notify.success('创建成功');
                    })
                }else if (vm === "update"){
                    putObj(this.form).then(() => {
                        this.getList();
                        this.onCancel();
                        this.$notify.closeAll();
                        this.$notify.success('更新成功');
                    })
                }
            },
            //取得判断人id
            getUserSpecialId(vm){
                let cResult = "";
                if(vm === "部门领导"){
                    if(this.form.deptLeaderId === undefined || this.form.deptLeaderId === null || this.form.deptLeaderId === ""){
                    }else {
                        cResult = this.form.deptLeaderId;
                    }
                }else if(vm === "奖金管理员"){
                    if(this.form.deptJjadminId === undefined || this.form.deptJjadminId === null || this.form.deptJjadminId === ""){
                    }else {
                        cResult = this.form.deptJjadminId;
                    }
                }
                return cResult;
            },
            onCancel() {
                this.formEdit = true
                this.formStatus = ''
            },
            resetForm() {
                this.form = {
                    parentId: this.currentId,
                    deptLeaderId: "",
                    deptLeaderName: "",

                    deptLeaderNames:"",
                    deptLeaderIds:"",

                    deptJjadminId: "",
                    deptJjadminName: "",

                    deptJjfafangId:"",
                    deptJjfafangName:"",

                    deptHtruadminId:"",
                    deptHtruadminName:"",

                    deptRckhadminId:"",
                    deptRckhadminName:"",

                    deptXrckhadminId:"",
                    deptXrckhadminName:"",

                    //评分等级
                    deptPfdjadminId:"",
                    deptPfdjadminName:"",

                    deptJcrckhadminId:"",
                    deptJcrckhadminName:"",
                }
            },
            /*
            * 20210913 说明
            * 1.现逻辑屏蔽 奖金发放
            * 2.原逻辑奖金管理员唯一验证 去掉此逻辑 update1、create1不要删除吖~_~
            * */
            // 修改(请不要删除）
            update1() {
                this.$refs.form.validate((valid) => {
                    if (!valid) return

                    const cLeader = this.getUserSpecialId("部门领导");
                    const cLeaderJj = this.getUserSpecialId("奖金管理员");

                    //部门领导验证
                    if(cLeader !== "")
                    {
                        haveRepetManger(this.currentId,cLeader,"update","部门领导").then(res =>{
                            const cListLeader = res.data.data;
                            if(cListLeader.length > 0){
                                this.$notify.closeAll();
                                this.$notify.error(cListLeader[0].deptLeaderName + "已是" + cListLeader[0].deptName + "领导，请重新选择！");
                            }
                            else //没有重复
                            {  ////console.log("2 部门领导不为空，没有重复的")
                                //验证奖金管理员
                                if( cLeaderJj !==""){
                                    haveRepetManger(this.currentId,cLeaderJj,"update","奖金管理员").then(resj =>{
                                        const cListJj = resj.data.data;
                                        if(cListJj.length > 0){
                                            this.$notify.closeAll();
                                            this.$notify.error(cListJj[0].deptJjadminName + "已是" + cListJj[0].deptName + "奖金管理员，请重新选择！");
                                        }
                                        else //奖金管理员不重复，走原逻辑
                                        {
                                            ////console.log("4,部门领导不为空，没有重复的，奖金管理员不重复")
                                            // return;
                                            this.addOrUpdate("update");
                                        }
                                    })
                                }
                                else //走原逻辑
                                {
                                    ////console.log("3,部门领导不为空，奖金管理员空")
                                    // return;
                                    this.addOrUpdate("update");
                                }

                            }
                        })
                    }
                    else  //部门领导为空，验证奖金管理员
                    {
                        if(cLeaderJj !==""){
                            haveRepetManger(this.currentId,cLeaderJj,"update","奖金管理员").then(resj =>{
                                const cListJj = resj.data.data;
                                if(cListJj.length > 0){
                                    this.$notify.closeAll();
                                    this.$notify.error(cListJj[0].deptJjadminName + "已是" + cListJj[0].deptName + "奖金管理员，请重新选择！");
                                }
                                else //奖金管理员不重复，走原逻辑
                                {
                                    ////console.log("5,部门领导为空，奖金管理员不重复")
                                    // return;
                                    this.addOrUpdate("update");
                                }
                            })
                        }
                        else //奖金管理员为空，走原逻辑
                        {
                            ////console.log("1,部门领导空，奖金管理员空")
                            // return;
                            this.addOrUpdate("update");
                        }
                    }

                    // putObj(this.form).then(() => {
                    //   this.getList()
                    //   this.onCancel()
                    //   this.$notify.success('更新成功')
                    // })
                })
            },

            // 添加（请不要删除）
            create1() {
                this.$refs.form.validate((valid) => {
                    if (!valid) return;

                    const cLeader = this.getUserSpecialId("部门领导");
                    const cLeaderJj = this.getUserSpecialId("奖金管理员");

                    //部门领导验证
                    if(cLeader !== ""){
                        haveRepetManger(this.currentId,cLeader,"add","部门领导").then(res =>{
                            const cListLeader = res.data.data;

                            if(cListLeader.length > 0){
                                this.$notify.closeAll();
                                this.$notify.error(cListLeader[0].deptLeaderName + "已是" + cListLeader[0].deptName + "领导，请重新选择！");
                            }
                            else //没有重复
                            {
                                ////console.log("2 部门领导不为空，没有重复的")
                                //验证奖金管理员
                                if( cLeaderJj !==""){
                                    haveRepetManger(this.currentId,cLeaderJj,"add","奖金管理员").then(resj =>{
                                        const cListJj = resj.data.data;
                                        if(cListJj.length > 0){
                                            this.$notify.closeAll();
                                            this.$notify.error(cListJj[0].deptJjadminName + "已是" + cListJj[0].deptName + "奖金管理员，请重新选择！");
                                        }
                                        else //奖金管理员不重复，走原逻辑
                                        {
                                            ////console.log("4,部门领导不为空，没有重复的，奖金管理员不重复")
                                            // return;
                                            this.addOrUpdate("add");
                                        }
                                    })

                                }
                                else //走原逻辑
                                {
                                    ////console.log("3,部门领导不为空，奖金管理员空")
                                    // return;
                                    this.addOrUpdate("add");
                                }
                            }
                        })

                    }
                    else  //部门领导为空，验证奖金管理员
                    {
                        if(cLeaderJj !==""){
                            haveRepetManger(this.currentId,cLeaderJj,"add","奖金管理员").then(resj =>{
                                const cListJj = resj.data.data;
                                if(cListJj.length > 0){
                                    this.$notify.closeAll();
                                    this.$notify.error(cListJj[0].deptJjadminName + "已是" + cListJj[0].deptName + "奖金管理员，请重新选择！");
                                }
                                else //奖金管理员不重复，走原逻辑
                                {
                                    ////console.log("5,部门领导为空，奖金管理员不重复")
                                    // return;
                                    this.addOrUpdate("add");
                                }
                            })
                        }
                        else //奖金管理员为空，走原逻辑
                        {
                            ////console.log("1,部门领导空，奖金管理员空")
                            // return;
                            this.addOrUpdate("add");
                        }
                    }

                    // addObj(this.form).then(() => {
                    //   this.getList()
                    //   this.onCancel()
                    //   this.$notify.success('创建成功')
                    //
                    // })
                })
            },


        }
    }
</script>



